$.ajaxSetup({
    dataType: "json", // 服务端返回的数据为json
    contentType: "application/json",
    processData: false,
    beforeSend(_, {data}) {
        this.data = JSON.stringify(data)
    },
    success(res) {
        return Promise.resolve(res)
    },// 传递给服务端的数据编码是json
    error(resp) {
        const {status, responseText} = resp;
        if (status === 401) {
            location.href = "/site/login.html"
        } else {
            alert(responseText);
        }
        return Promise.reject(resp);
    }
});


// 获取表单数据
function getFormData(form) {
    return form.serializeArray()
        .reduce((data, {name, value}) => {
            data[name] = value;
            return data;
        }, {});
}
